<template>
<l-layout v-if="ready" class="l-tab-page" >
    <l-panel  style="padding:0;" >
        <template #toolRight >
            <el-button-group>
                <el-button size="mini" icon="el-icon-refresh-left" @click="hanleSearch"></el-button>
            </el-button-group>
        </template>
        <div class="l-rblock" >
            <l-table 
                :columns="columns" 
                :dataSource="tableData" 
                :loading="tableLoading"
                :isPage="true"
                :pageTotal="tableTotal"
                :tablePage.sync="tableCurrentPage"
                @loadPageData="turnTablePage" 
                >
            </l-table>
        </div>
    </l-panel>
</l-layout>
</template>

<script>
const api = window.$api.sass.tenantHistory
export default {
    data () {
        return {            
            tableLoading:false,
            tableData:[],
            tableTotal:0,
            tablePageSize:50,
            tableCurrentPage:1,
            columns:[
                {label:'类型',prop:'f_Type',width:120,align:'left',
                    formatter:function({cellValue}){
                        switch(cellValue){
                            case 0:
                                return '完成'
                            case 1:
                                return '同步表结构'
                            case 2:
                                return '同步数据'
                            case 3:
                                return '创建账号'
                            case 4:
                                return '同步菜单'
                        }
                    }
                },
                {label:'操作人',prop:'f_CreateUserName',width:120,align:'left'},
                {label:'时间',prop:'f_CreateTime',width:160,align:'left',dataType:'datetime'},
                {label:'内容',prop:'f_Content',minWidth:120,align:'left'},
            ],

            tenantId:'',

            ready:false
        };
    },
    created () {
    },
    mounted () {
    },
    methods:{
        async init(tenantId){
            this.ready = false
            this.tenantId = tenantId
            this.tableLoading = true
            await this.loadTableData()   
            this.ready = true       
        },
        async loadTableData(isNotFirst){
            if(!isNotFirst){
                this.tableCurrentPage = 1
            }
            this.tableLoading = true
            let queryData = {
                rows:this.tablePageSize,
                page:this.tableCurrentPage,
                sidx:'f_CreateTime Desc',
                f_TenantId:this.tenantId,
            }
            const data = await this.$awaitWraper(api.getPage(queryData))
            this.tableData = data.rows
            this.tableTotal = data.records
            this.tableLoading = false
        },
        turnTablePage({rows}){
            this.tablePageSize = rows
            this.loadTableData(true)
        },
        hanleSearch(){
            this.loadTableData()
        },
        resetForm(){
            this.tableCurrentPage = 1
            this.tenantId = ''
            this.columns = []
            this.tableData = []
            this.tableTotal = 0
        }
    }
}
</script>